import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class WebViewDemoPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => new _WebViewDemoPagePageState();
}
class _WebViewDemoPagePageState extends State<WebViewDemoPage> {


  FlutterWebviewPlugin flutterWebviewPlugin = FlutterWebviewPlugin();

  var urlString = "http://www.gonghuizhudi.com?appName=yunding";

  @override
  void initState() {

    super.initState();
    //监听页面状态改变
    flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged wvs) {
      print(wvs.type);
    });
    
    flutterWebviewPlugin.onUrlChanged.listen((String url) {
      print('改变连接'+ url);
    });

    //监听页面滚动事件
    flutterWebviewPlugin.onScrollYChanged.listen((double offsetY) {
      print('offsetY: $offsetY');
    });

    flutterWebviewPlugin.onScrollXChanged.listen((double offsetX) {
      print('offsetX: $offsetX');
    });

  }

  launchUrl() {
    setState(() {
      flutterWebviewPlugin.reloadUrl(urlString);
    });
  }

  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: new Text('云钉绘图'),
        bottom: new PreferredSize(
            preferredSize: const Size.fromHeight(1.0),

        ),

      ),
      body: SafeArea(
        child: WebviewScaffold(
          url: urlString,
          withZoom: true,
          withJavascript: true,
          withLocalStorage: true,
        ),
        bottom: true,
        left: true,
        right: true,
        top: true,
      ),


    );

    return WebviewScaffold(
      appBar: AppBar(
        title: new Text('云钉绘途')
      ),
      url: urlString,
      withZoom: true,
      withLocalStorage: true,
      enableAppScheme: true,
      withJavascript: true,

    );
  }
}

